import db from '../../config/sqlcfg';
import { TransactionMessage } from '../../Interface/TransactionMessage';

class EthTransfer {

  private static table: string = 'eth_transfer';

  /**
   * 保存[转移]或[提币]记录
   * @static
   * @param {number} type
   * @param {number} coinType
   * @param {TransactionMessage} transaction
   * @returns
   * @memberof EthTransfer
   */
  static async save(type: number, coinType: number, transaction: TransactionMessage, msg: string) {
    let save = await db.query(`insert into ${this.table} 
      set 
        \`type\` = ${type},
        \`coin_type\` = ${coinType},
        \`block\` = ${transaction.blockNum},
        \`hash\` = '${transaction.hash}',
        \`from\` = '${transaction.from}',
        \`to\` = '${transaction.to}',
        \`amount\` = '${transaction.amount}',
        \`msg\` = '${msg}'
    `);
    return save;
  }

}

export default EthTransfer;
